<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title2</title>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/jquery.session@1.0.0/jquery.session.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
</head>
<body>
<p id="login_res"> msg </p>
<button id="loginBtn">登录</button>
<button id="openConsole">open console</button>
<button id="sessionPage">sessionPage</button>
<hr/>
<button id="sessionShow">sessionShow</button>
<button id="sessionSet">sessionSet</button>
<hr/>
<button id="cookieShow">cookieShow</button>
<button id="cookieSet">cookieSet</button>
<hr/>
</body>

<script>
    $(document).ready(function () {
        $("#loginBtn").click(() => {
            qqq()
        })
        $("#openConsole").click(() => {
            window.open('/ui/#/console/' + 2, '_blank',
                'menubar=no,location=no,resizable=yes,scrollbars=yes,status=no');
        })
        $("#sessionPage").click(() => {
            window.open('/chao2/cookie_test', '_blank',
                'menubar=no,location=no,resizable=yes,scrollbars=yes,status=no');
        })
        $("#sessionShow").click(() => {
            console.log($.session.get('vmware_soap_session'))
            console.log($.session.get('vmware_client'))
        })
        $("#sessionSet").click(() => {
            console.log($.session.set('vmware_soap_session', "\"93a7ef403bedff5922346dc578fe1082a66bfbf6\""))
            console.log($.session.set('vmware_client', "VMware"))
        })
        $("#cookieSet").click(() => {
            $.cookie('vmware_soap_session', "\"93a7ef403bedff5922346dc578fe1082a66bfbf6\"", {path: '/'})
            $.cookie('vmware_client', "VMware", {path: '/'})
        })
        $("#cookieShow").click(() => {
            console.log($.cookie('vmware_soap_session'))
            console.log($.cookie('vmware_client'))
        })
    });

    function getData() {
        const  password = ''
        let body = `<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Header><operationID>esxui-898c</operationID></Header><Body><Login xmlns="urn:vim25"><_this type="SessionManager">ha-sessionmgr</_this><userName>root</userName><password>${password}</password><locale>zh-CN</locale></Login></Body></Envelope>`;
        return body;
    }

    function qqq() {

        let data = getData();
        data = data.replaceAll("\r\n", "")
        data = data.replaceAll("\n", "")
        console.log(data)
        $.ajax({
            url: "http://localhost:2443/sdk/", // 请求的URL
            type: "POST", // 请求类型，默认为GET
            data: data,
            xhrFields: {
                withCredentials: false // 发送Ajax时，Request header中会带上 Cookie 信息。
            },
            success: function (response) { // 请求成功时的回调函数
                console.log(response); // 在控制台打印服务器返回的数据
                $("#login_res").text(response)
            },
            error: function (xhr, status, error) { // 请求失败时的回调函数
                console.error(error); // 在控制台打印错误信息据
                $("#login_res").append(error)
                $("#login_res").append(xhr.responseText)
            }
        });
    }
</script>
</html>